package com.jzo2o.customer.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jzo2o.common.utils.BeanUtils;
import com.jzo2o.customer.mapper.WorkerCertificationMapper;
import com.jzo2o.customer.model.domain.WorkerCertification;
import com.jzo2o.customer.model.dto.request.WorkerCertificationAuditAddReqDTO;
import com.jzo2o.mvc.utils.UserContext;
import org.springframework.stereotype.Service;

@Service
public class ICertificationAuditServiceImpl extends ServiceImpl<WorkerCertificationMapper, WorkerCertification> implements ICertificationAuditService {
    @Override
    public void certification(WorkerCertificationAuditAddReqDTO workerCertificationAuditAddReqDTO) {
        Long count = lambdaQuery().eq(WorkerCertification::getIdCardNo, workerCertificationAuditAddReqDTO.getIdCardNo())
                .eq(WorkerCertification::getId, workerCertificationAuditAddReqDTO.getServeProviderId())
                .count();
        if (count > 0) {
            throw new RuntimeException("认证信息已存在");
        }
        WorkerCertification workerCertification = BeanUtils.copyProperties(workerCertificationAuditAddReqDTO, WorkerCertification.class);
        workerCertification.setCertificationStatus(1);
        workerCertification.setId(UserContext.currentUserId());
        this.save(workerCertification);
    }
}
